/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmRegisterContato.java
 *
 * Created on 25/01/2010, 08:31:01
 */

package forms;

import classes.tecnico;
import classes.tecnicos;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import rad.Java.Common.DB.Database;

/**
 *
 * @author rogerio
 */
public class frmRegisterTecnico extends javax.swing.JFrame {

    private boolean status = true;
    private DefaultTableModel dtmTecnico;
    private tecnicos listTecnico;
    private tecnico t;
    /** Creates new form frmRegisterContato */
    public frmRegisterTecnico() {
        initComponents();
        listTecnico = new tecnicos();
        dtmTecnico  = new DefaultTableModel();
        t           = new tecnico();
        btnEditar.setEnabled(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jtpTecnico = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtPesquisa = new javax.swing.JTextField();
        rbdCpf = new javax.swing.JRadioButton();
        btnPesquisar = new javax.swing.JButton();
        rbdNome = new javax.swing.JRadioButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tbTecnico = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jLabel25 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        txtTecnicoDatePreenche = new javax.swing.JFormattedTextField();
        txtTecnicoAreaResp = new javax.swing.JTextField();
        txtTecnicoNome = new javax.swing.JTextField();
        txtTecnicoRgConselho = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        txtTecnicoSsp = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        txtTecnicoRG = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        txtTecnicoFormProfissional = new javax.swing.JTextField();
        txtTecnicoCpf = new javax.swing.JFormattedTextField();
        btnSalvar = new javax.swing.JButton();
        btnEditar = new javax.swing.JButton();
        btnNovo = new javax.swing.JButton();
        btnDeletar = new javax.swing.JButton();
        btnDeletar1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastro de Técnico");
        setResizable(false);

        jtpTecnico.setName("jtpTecnico"); // NOI18N

        jPanel2.setName("jPanel2"); // NOI18N

        jLabel1.setText("Pesquisa:");
        jLabel1.setName("jLabel1"); // NOI18N

        txtPesquisa.setName("txtPesquisa"); // NOI18N

        buttonGroup1.add(rbdCpf);
        rbdCpf.setText("CPF");
        rbdCpf.setName("rbdCpf"); // NOI18N

        btnPesquisar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/forms/resources/search_32x32.png"))); // NOI18N
        btnPesquisar.setToolTipText("Pesquisar");
        btnPesquisar.setName("btnPesquisar"); // NOI18N
        btnPesquisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPesquisarActionPerformed(evt);
            }
        });

        buttonGroup1.add(rbdNome);
        rbdNome.setSelected(true);
        rbdNome.setText("Nome");
        rbdNome.setName("rbdNome"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        tbTecnico.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        tbTecnico.setName("tbTecnico"); // NOI18N
        jScrollPane2.setViewportView(tbTecnico);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtPesquisa, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(rbdNome)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rbdCpf)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnPesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtPesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel1)
                        .addComponent(rbdCpf)
                        .addComponent(rbdNome))
                    .addComponent(btnPesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE)
                .addContainerGap())
        );

        jtpTecnico.addTab("Pesquisa", jPanel2);

        jPanel1.setName("jPanel1"); // NOI18N

        jLabel25.setText("DATA DO PREENCHIMENTO:");
        jLabel25.setName("jLabel25"); // NOI18N

        jLabel24.setText("ÁREA DE RESPONSABILIDADE:");
        jLabel24.setName("jLabel24"); // NOI18N

        try {
            txtTecnicoDatePreenche.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        txtTecnicoDatePreenche.setName("txtTecnicoDatePreenche"); // NOI18N

        txtTecnicoAreaResp.setName("txtTecnicoAreaResp"); // NOI18N

        txtTecnicoNome.setName("txtTecnicoNome"); // NOI18N

        txtTecnicoRgConselho.setName("txtTecnicoRgConselho"); // NOI18N

        jLabel18.setText("RG. CONSELHO:");
        jLabel18.setName("jLabel18"); // NOI18N

        txtTecnicoSsp.setName("txtTecnicoSsp"); // NOI18N

        jLabel21.setText("SSP:");
        jLabel21.setName("jLabel21"); // NOI18N

        txtTecnicoRG.setName("txtTecnicoRG"); // NOI18N

        jLabel16.setText("NOME:");
        jLabel16.setName("jLabel16"); // NOI18N

        jLabel17.setText("CPF:");
        jLabel17.setName("jLabel17"); // NOI18N

        jLabel20.setText("RG:");
        jLabel20.setName("jLabel20"); // NOI18N

        jLabel23.setText("FORMAÇÃO PROFISSIONAL:");
        jLabel23.setName("jLabel23"); // NOI18N

        txtTecnicoFormProfissional.setName("txtTecnicoFormProfissional"); // NOI18N

        try {
            txtTecnicoCpf.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        txtTecnicoCpf.setName("txtTecnicoCpf"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel20, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel24)
                                    .addComponent(jLabel23))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtTecnicoFormProfissional, javax.swing.GroupLayout.DEFAULT_SIZE, 421, Short.MAX_VALUE)
                                    .addComponent(txtTecnicoAreaResp, javax.swing.GroupLayout.DEFAULT_SIZE, 421, Short.MAX_VALUE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel16)
                                    .addComponent(jLabel17))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(txtTecnicoRG)
                                            .addComponent(txtTecnicoCpf, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addComponent(jLabel18)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(txtTecnicoRgConselho))
                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addComponent(jLabel21)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(txtTecnicoSsp, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(jLabel25)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(txtTecnicoDatePreenche, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                    .addComponent(txtTecnicoNome))))
                        .addGap(110, 110, 110)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(txtTecnicoNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(jLabel18)
                    .addComponent(txtTecnicoRgConselho, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtTecnicoCpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel20)
                    .addComponent(txtTecnicoRG, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel21)
                    .addComponent(txtTecnicoSsp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtTecnicoDatePreenche, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel25))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel23)
                    .addComponent(txtTecnicoFormProfissional, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(8, 8, 8)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel24)
                    .addComponent(txtTecnicoAreaResp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(27, Short.MAX_VALUE))
        );

        jtpTecnico.addTab("Principal", jPanel1);

        btnSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/forms/resources/save_32x32.png"))); // NOI18N
        btnSalvar.setToolTipText("Salvar");
        btnSalvar.setName("btnSalvar"); // NOI18N
        btnSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalvarActionPerformed(evt);
            }
        });

        btnEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/forms/resources/edit_32x32.png"))); // NOI18N
        btnEditar.setToolTipText("Editar");
        btnEditar.setName("btnEditar"); // NOI18N
        btnEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditarActionPerformed(evt);
            }
        });

        btnNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/forms/resources/new_32x32.png"))); // NOI18N
        btnNovo.setToolTipText("Novo");
        btnNovo.setName("btnNovo"); // NOI18N
        btnNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNovoActionPerformed(evt);
            }
        });

        btnDeletar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/forms/resources/delete_32x32.png"))); // NOI18N
        btnDeletar.setToolTipText("Deletar");
        btnDeletar.setName("btnDeletar"); // NOI18N
        btnDeletar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeletarActionPerformed(evt);
            }
        });

        btnDeletar1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/forms/resources/exit_32x32.png"))); // NOI18N
        btnDeletar1.setToolTipText("Sair");
        btnDeletar1.setName("btnExit"); // NOI18N
        btnDeletar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeletar1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jtpTecnico, javax.swing.GroupLayout.PREFERRED_SIZE, 554, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnNovo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnEditar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnSalvar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnDeletar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnDeletar1, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(104, 104, 104))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnEditar, btnNovo, btnSalvar});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jtpTecnico, javax.swing.GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(btnSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnEditar, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnNovo, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnDeletar1, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnDeletar, javax.swing.GroupLayout.Alignment.LEADING))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btnDeletar, btnDeletar1, btnEditar, btnNovo, btnSalvar});

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-579)/2, (screenSize.height-335)/2, 579, 335);
    }// </editor-fold>//GEN-END:initComponents

    private void btnNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNovoActionPerformed
        clear();
        jtpTecnico.setSelectedIndex(1);
        txtTecnicoNome.requestFocus();
        status = true;
        t.clear();

        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        txtTecnicoDatePreenche.setText(sdf.format(new Date()));
    }//GEN-LAST:event_btnNovoActionPerformed

    private void btnEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditarActionPerformed
        try {
            editar();
        } catch (SQLException ex) {
            Logger.getLogger(frmRegisterTecnico.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btnEditarActionPerformed

    private void btnSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarActionPerformed
        salvar();
    }//GEN-LAST:event_btnSalvarActionPerformed

    private void btnPesquisarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPesquisarActionPerformed
        pesquisa();
    }//GEN-LAST:event_btnPesquisarActionPerformed

    private void btnDeletarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeletarActionPerformed
        try {
            deletar();
        } catch (SQLException ex) {
            Logger.getLogger(frmRegisterTecnico.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event_btnDeletarActionPerformed

    private void btnDeletar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeletar1ActionPerformed
        this.dispose();
}//GEN-LAST:event_btnDeletar1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new frmRegisterTecnico().setVisible(true);
            }
        });
    }

    //<editor-fold defaultstate="collapsed" desc="Function">
    private void fillGridView() throws SQLException
    {
        String[] colunas = new String[]{"Código","Nome","CPF"};
        String[][] dados = new String[][]{{}};
        dtmTecnico = new DefaultTableModel(dados, colunas);

        String tecnico[] = new String[3];
        int aux = 0;
        for(int i = 0; i < listTecnico.count(); i++)
        {
            tecnico[0] = listTecnico.get(i).getId();
            tecnico[1] = listTecnico.get(i).getTecnico_name();
            tecnico[2] = listTecnico.get(i).getTecnico_cpf();
            dtmTecnico.addRow(tecnico);
            if (i == 0){
               dtmTecnico.removeRow(0);
            }
        }
        
        tbTecnico.setModel(dtmTecnico);
        tbTecnico.repaint();
    }

    private void salvar()
    {
        t.setTecnico_areaResposabilidade(txtTecnicoAreaResp.getText());
        t.setTecnico_cpf(txtTecnicoCpf.getText());
        t.setTecnico_formacaoProfissional(txtTecnicoFormProfissional.getText());
        t.setTecnico_name(txtTecnicoNome.getText());
        t.setTecnico_rg(txtTecnicoRG.getText());
        t.setTecnico_rgConselho(txtTecnicoRgConselho.getText());
        t.setTecnico_ssp(txtTecnicoSsp.getText());
        t.setTecnico_datePreenchimento(txtTecnicoDatePreenche.getText());
        t.setEnable(true);

        String mensagem = "";
        if(status){
            if(t.save())
               mensagem = "Registro salvo com sucesso";
            else
               mensagem = "Erro ao tentar gravar o registro";
         }
         else{
            if(t.update())
               mensagem = "Registro salvo com sucesso";
            else
               mensagem = "Erro ao tentar gravar o registro";
         }
         JOptionPane.showMessageDialog(null,mensagem);
         status = true;
         limpaDVG();
         clear();
         btnEditar.setEnabled(false);
         jtpTecnico.setSelectedIndex(0);
    }

    private void editar() throws SQLException
    {
         t.setId(idGredViewSelectedRow());
         if(!t.get())
         {
             JOptionPane.showMessageDialog(null, "Erro:"+ t.getErrorMessage());
             return;
         }
         status = false;
         clear();
         fillEdits();
         limpaDVG();
         btnEditar.setEnabled(false);
         jtpTecnico.setSelectedIndex(1);
         status = false;
    }

    public void fillEdits()
    {
        txtTecnicoAreaResp.setText(t.getTecnico_areaResposabilidade());
        txtTecnicoCpf.setText(t.getTecnico_cpf());
        txtTecnicoDatePreenche.setText(t.getTecnico_datePreenchimento());
        txtTecnicoFormProfissional.setText(t.getTecnico_formacaoProfissional());
        txtTecnicoNome.setText(t.getTecnico_name());
        txtTecnicoRG.setText(t.getTecnico_rg());
        txtTecnicoRgConselho.setText(t.getTecnico_rgConselho());
        txtTecnicoSsp.setText(t.getTecnico_ssp());
    }

    private String idGredViewSelectedRow()
    {
        int  index = tbTecnico.getSelectedRow();
        String id  = tbTecnico.getValueAt(index,0).toString();
        return id;
    }

    private void clear()
    {

        txtTecnicoAreaResp.setText("");
        txtTecnicoCpf.setText("");
        txtTecnicoDatePreenche.setText("");
        txtTecnicoFormProfissional.setText("");
        txtTecnicoNome.setText("");
        txtTecnicoRG.setText("");
        txtTecnicoRgConselho.setText("");
        txtTecnicoSsp.setText("");
        txtPesquisa.setText("");

    }

     private void limpaDVG()
    {
        String[] colunas = new String[]{"Codigo","Estabelecimento","Ano","Tecnico"};
        String[][] dados = new String[][]{{}};
        dtmTecnico = new DefaultTableModel(dados, colunas);
        tbTecnico.setModel(dtmTecnico);
    }

    private void pesquisa()
    {
        String sql;
        if(txtPesquisa.toString().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Preencha o campo pesquisa");
            return;
        }

        if (rbdNome.isSelected()) {
            sql = "tecnico_name LIKE '" + txtPesquisa.getText()+"%'";
        } else {
            sql = "tecnico_cpf LIKE '" + txtPesquisa.getText()+"%'";
        }
        try {
            if (!listTecnico.fillList(sql)) {
                JOptionPane.showMessageDialog(null, "Erro " + Database.ErrorMessage);
                return;
            }
            fillGridView();
            btnEditar.setEnabled(true);
        } catch (SQLException ex) {
            Logger.getLogger(frmRegisterTecnico.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    //</editor-fold>

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnDeletar;
    private javax.swing.JButton btnDeletar1;
    private javax.swing.JButton btnEditar;
    private javax.swing.JButton btnNovo;
    private javax.swing.JButton btnPesquisar;
    private javax.swing.JButton btnSalvar;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jtpTecnico;
    private javax.swing.JRadioButton rbdCpf;
    private javax.swing.JRadioButton rbdNome;
    private javax.swing.JTable tbTecnico;
    private javax.swing.JTextField txtPesquisa;
    private javax.swing.JTextField txtTecnicoAreaResp;
    private javax.swing.JFormattedTextField txtTecnicoCpf;
    private javax.swing.JFormattedTextField txtTecnicoDatePreenche;
    private javax.swing.JTextField txtTecnicoFormProfissional;
    private javax.swing.JTextField txtTecnicoNome;
    private javax.swing.JTextField txtTecnicoRG;
    private javax.swing.JTextField txtTecnicoRgConselho;
    private javax.swing.JTextField txtTecnicoSsp;
    // End of variables declaration//GEN-END:variables

    private boolean deletar() throws SQLException {
        int option = JOptionPane.showConfirmDialog(null, "Deseja realmente excluir este registro ?");
        if(option == 0)
        {
            t.setId(idGredViewSelectedRow());
            t.get();
            t.setEnable(false);
            if(!t.update())
                JOptionPane.showMessageDialog(null, "Erro ao tentar deletar o registro");
            listTecnico.fillList();
            fillGridView();
        }
        return true;
    }

}
